{% extends "base.html" %}
{% block content %}
{% ifequal is_con 0 %}
<script type="text/javascript" src="/static/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="/static/js/jquery-ui-1.8.16.custom.min.js"></script>
<link href="/static/css/jquery-ui-1.8.16.custom.css" rel="stylesheet" type="text/css" />
<div class="form-div" style="margin:10px;">
  <form action='' method='get' name="searchForm">
	<table>
		<tr>
			<td style="border:0px;padding:3px;">
				<img src="/static/images/icon_search.gif" width="26" height="22" border="0" alt="SEARCH">
			</td>
			<td  style="border:0px;padding:3px;">
				Date Start:<input type='text' name='starttime' id='start'>
				Date End:<input type='text' name='endtime' id='end'>
				Program:<select name="p_id" id="p_id" style="color:#CC33FF" onclick='$("input#search").click()'>
							<option value="0" selected="selected">All</option>
							{% for p in project_list %}
								<option value="{{p.id}}" {% ifequal p.id p_id %} selected="selected" {% endifequal %}>{{p.name}}</option>
							{% endfor %}
						</select>
				<input type='button' id="search" value='Search'/>
			</td>
		</tr>
		<tr>
			<td style="border:0px;padding:3px;"></td>
			<td colspan='10' style="border:0px;padding:3px;">
				<div class="selectdate" days='7'>Weekly</div>
				<div class="selectdate" days='14'>Bi-weekly</div>
				<div class="selectdate" days='30'>Monthly</div>
				<div class="selectdate" days='90'>Season</div>
				<div class="selectdate" days='180'>Half-yearly</div>
				<div class="selectdate" days='365'>Yearly</div>
			</td>
		</tr>
	</table>
  </form>
  <form action="/report_export/" method='post' id='post_report'>
	<input type='hidden' name='d' value=''/>
	<input type='hidden' name='t' value=''/>
  </form>
</div>
<script type="text/javascript" src="/static/js/create_report_export.js"></script>
<script>
$(document).ready(
	function(){
    	$('#start').datepicker({"dateFormat": "yy-mm-dd",changeMonth:true,changeYear:true})
		$('#end').datepicker({"dateFormat": "yy-mm-dd",changeMonth:true,changeYear:true})
		var agodays = new Date(Date.parse(new Date().toString()) - 86400000*6);
		var year = agodays.getUTCFullYear()
		var month = (agodays.getUTCMonth()+1)>=10?(agodays.getUTCMonth()+1):'0'+(agodays.getUTCMonth()+1)
		var day = agodays.getUTCDate()>=10?agodays.getUTCDate():'0'+agodays.getUTCDate()
		var date = year+'-'+month+'-'+day
		$('#start').val(date)

		$('div.selectdate').click(function(){
			$('div.selectdate').removeClass('active_title')
			$('div.selectdate').css('background','')
			$(this).css('background','#defdef')
			$(this).addClass('active_title')
		})
	}
)
$("input#search").bind({
	click:function(){
		var t = this
		if(t.style.cursor == 'wait'){
			return false;
		}
		t.style.cursor = 'wait'
		var data = $('form[name="searchForm"]').serializeArray()
		var datas = {'is_con':1,'t':Math.random()}
		for(var i=0;i<data.length;i++){
			datas[data[i].name] = data[i].value
		}
		$.ajax({
			url:'',
			data:datas,
			type:'get',
			dataType:'html',
			success:function(e){
				t.style.cursor = 'pointer'
				$('#conreturn').html(e)
			}
		})
	}
})
</script>
{% endifequal %}
<style>
td{
	padding:2px;
	border:1px dotted #333;
}
th{
	background:#ffffcd;
	border:1px dotted #333;
	padding:2px;
}
.selectdate{
	width:auto;float:left;padding:3px;background:#fff;border:1px dotted #333;margin:2px;cursor:pointer;
}
.selectdate:hover{
	background:#defdef;
}
</style>
<div id="conreturn" style="margin:10px;">
	{%if error_info%}
		<span class='red'>{{error_info}}</span>
	{%else%}
	<table name='static_table' style="min-width:800px;">
		<tr>
			<td colspan="{{pro_len|add:'1'}}"  style="border:1px solid #333;">
				<table width='100%'>
				  <tr>
					<td colspan='2' align='left' style="line-height:25px;background:#ffffcd;border:0px;padding:3px;"></td>
					<td align='right' colspan='5' align='right' style="line-height:25px;background:#ffffcd;border:0px;padding:3px;">
						<strong><span id='university'></span></strong><br>
						<strong><span id='program'></span></strong>
					</td>
				  </tr>
				  <tr>
					<td colspan='2' align='left' style="line-height:25px;background:#ffffcd;border:0px;padding:3px;font-size:20px;"><strong id='report_title'>Attendance Report <span id='date_title'></span><span id='pro_title'></span></strong></td>
					<td colspan='16' align='right' style="line-height:25px;background:#ffffcd;border:0px;padding:3px;"><strong>Date:</strong>&nbsp;
					<span id="report_start">{{begin|date:"M d,Y"}}</span> - {{end|date:"M d,Y"}}</td>
				  </tr>
				</table>
			</td>
		</tr>
	{%if tol_ret%}
		<tr style="background:#defdef;line-height:30px;" flag='static'>
			<td style="line-height:30px;">&nbsp;</td>
			{%for pro in project_list%}
				<td align='center' style="line-height:30px;">{{pro.name}}</td>
			{%endfor%}
		</tr>
		{%for ret in tol_ret%}
			<tr bgcolor='#ddd' flag='year'>
				<td style="background:#dedede;line-height:25px;"><strong>{{ret.year}}</strong></td>
				<td style="background:#dedede;" colspan="{{pro_len}}"></td>
			</tr>
		{%for m in ret.month%}
			<tr flag='static'>
				<td align='right'>
				{%ifequal m.name 1%}January{%endifequal%}
				{%ifequal m.name 2%}February{%endifequal%}
				{%ifequal m.name 3%}March{%endifequal%}
				{%ifequal m.name 4%}April{%endifequal%}
				{%ifequal m.name 5%}May{%endifequal%}
				{%ifequal m.name 6%}June{%endifequal%}
				{%ifequal m.name 7%}July{%endifequal%}
				{%ifequal m.name 8%}August{%endifequal%}
				{%ifequal m.name 9%}September{%endifequal%}
				{%ifequal m.name 10%}October{%endifequal%}
				{%ifequal m.name 11%}November{%endifequal%}
				{%ifequal m.name 12%}December{%endifequal%}
				</td>
				{%for v in m.value%}
				<td align='center'>{{v}}</td>
				{%endfor%}
			</tr>
		{%endfor%}
		{%endfor%}
	{%else%}
		<tr>
			<td colspan='10' align='center'><span style="color:green;font-size:16px;line-height:30px;">No Result!</span></td>
		</tr>
	{%endif%}
	</table>
	{%endif%}
</div>
{{ttt}}
<script>
	var date_title = $('.active_title').text()
	var pro_title = $('#p_id option:selected').text()
	if(date_title){
		$('#date_title').html('('+date_title+')')
	}
	if($('#p_id option:selected').val()!=0){
		$('#pro_title').html(' -'+pro_title)
	}
{%if tol_ret%}
	var index
	$('tr[flag="static"]').each(function(){
		$(this).find('td').each(function(){
			if($(this).index()>0){
				$(this).addClass('static_'+$(this).index())
				index = $(this).index()
			}
		})
	})
	for(var i=1;i<=index;i++){
		var tolnum = 0;
		$('.static_'+i).each(function(){
			if(parseInt($(this).text())){
				tolnum += parseInt($(this).text())
			}
		})
		if(tolnum==0){
			$('.static_'+i).hide()
		}
	}
{%endif%}
var pro = parseInt($('#p_id').val())
if(school[pro]!=undefined){
	$('#university').text(school[pro][0])
	$('#program').text(school[pro][1])
}
</script>
{% endblock %}
